package com.lida.swagger.config;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * author: lida
 * create time: 2020-09-02 11:49
 * description: Swagger2的配置文件
 */
@SpringBootConfiguration
@EnableSwagger2     //开启 Swagger2
public class SwaggerConfig {

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)  //文档类型是 Swagger2 的类型
                .apiInfo(apiInfo())  //生成接口文档的信息
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.lida.swagger.controller"))
                .paths(PathSelectors.any())  //任何选中的 Controller 都要生成文档
                .build();   //构建这样一个对象
    }

    /**
     * 构建 API 文档信息的方法
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("李达的项目")  //文档的标题
                .description("chnws")   //文档的说明信息
                //.contact("lida")    //作者，已过时
                .contact(new Contact("lida", null, "1970939972@qq.com"))
                .version("001")   //文档的版本
                .build();
    }
}
